package com.resign.carl.command.example2;

import com.resign.carl.command.example1.api.Light;
import com.resign.carl.command.example1.api.impl.GarageDoor;
import com.resign.carl.command.example1.api.impl.GarageDoorOpenCommand;
import com.resign.carl.command.example1.api.impl.LightOnCommand;
import com.resign.carl.command.example2.api.CeilingFan;
import com.resign.carl.command.example2.api.RemoteControl;
import com.resign.carl.command.example2.api.Stereo;
import com.resign.carl.command.example2.api.impl.*;

/**
 * Created by carl.zhao on 2016/6/15.
 */
public class Client {

    public static void main(String[] args) {
        RemoteControl remoteControl = new RemoteControl();

        // 将所有的装置创建在合适的位置
        Light livingRoomLight = new Light("Living Room");
        Light kitchenLigth = new Light("Kitchen");
        CeilingFan ceilingFan = new CeilingFan("Living Room");
        GarageDoor garageDoor = new GarageDoor();
        Stereo stereo = new Stereo("Living Room");

        // 创建所有的电灯命令对象
        LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight);
        LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight);
        LightOnCommand kitchenRoomLightOn = new LightOnCommand(kitchenLigth);
        LightOffCommand kitchenRoomLightOff = new LightOffCommand(kitchenLigth);

        // 创建吊扇的开与关命令
        CeilingFanOnCommand ceilingFanOn = new CeilingFanOnCommand(ceilingFan);
        CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan);

        // 创建车库门的上与下命令
        GarageDoorOpenCommand garageDoorOpen = new GarageDoorOpenCommand(garageDoor);
        GarageDoorCloseCommand garageDoorClose = new GarageDoorCloseCommand(garageDoor);;

        // 创建音响的开与关命令
        StereoOnWithCDCommand stereoOnWithCD = new StereoOnWithCDCommand(stereo);
        StereoOffCommand stereoOff = new StereoOffCommand(stereo);

        // 现在已经有了全部的命令，可以将它们加载到遥控器插槽中
        remoteControl.setCommands(0, livingRoomLightOn, livingRoomLightOff);
        remoteControl.setCommands(1, kitchenRoomLightOn, kitchenRoomLightOff);
        remoteControl.setCommands(2, ceilingFanOn, ceilingFanOff);
        remoteControl.setCommands(3, garageDoorOpen,garageDoorClose);
        remoteControl.setCommands(4, stereoOnWithCD, stereoOff);

        System.out.println(remoteControl);
        remoteControl.onButtonWasPushed(0);
        remoteControl.offButtonWasPushed(0);
        remoteControl.onButtonWasPushed(1);
        remoteControl.offButtonWasPushed(1);
        remoteControl.onButtonWasPushed(2);
        remoteControl.offButtonWasPushed(2);
        remoteControl.onButtonWasPushed(3);
        remoteControl.offButtonWasPushed(3);
        remoteControl.onButtonWasPushed(4);
        remoteControl.offButtonWasPushed(4);


    }
}
